package fp.poczadly.client.event;

import com.google.gwt.event.shared.GwtEvent;

import fp.poczadly.shared.User;
import fp.poczadly.shared.Utils;

public class LogoutEvent extends GwtEvent<LogoutEventHandler> {

	public static Type<LogoutEventHandler> TYPE = new Type<LogoutEventHandler>();
	
	private User user = null;
	
	public LogoutEvent( User user ) {
	}
	
	@Override
	public Type<LogoutEventHandler> getAssociatedType() {
		return TYPE;
	}

	@Override
	protected void dispatch( LogoutEventHandler handler ) {
		handler.removeUser( this );
	}
	
	public User getLoggedUser() throws NullPointerException {
		if( user == null )
			throw new NullPointerException( Utils.USER_IS_ALREADY_LOGED );
		
		return user;
	}

	
}
